<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class ConfigRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rule = ['config_title'=>'required'];
        if (!request()->route()->hasParameter('name')){
            $rule['config_name'] = ['required','alpha_start','unique:sys_config,name'];
        }

        return $rule;
    }

    public function messages()
    {
        return [
            'required'=>':attribute不能为空',
            'alpha_start'=>':attribute必须以字母开头仅包含字母数字或下划线',
            'unique'=>':attribute已存在',
        ];
    }

    public function attributes()
    {
        return [
            'config_name'=>'配置标识',
            'config_title'=>'配置标题',
        ];
    }
}
